/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2024-10-12
 * Time: 19:09
 */
public class test {
    //LeetCode LCR069  山峰数组的封顶索引  符合下列属性的数组 arr 称为 山峰数组（山脉数组） ：


    //枚举：
    public int peakIndexInMountainArray(int[] arr) {
        int n = arr.length;
        int ret=-1;
        for(int i=0;i<n;i++){
            if(arr[i]>arr[i+1]){
                ret = i;
                break;
            }
        }
        return  ret;
    }

    //二分查找:
    public int peakIndexInMountainArray2(int[] arr) {
        int n = arr.length;
        int left = 1;
        int right= n-2;
        int ret = 0;
        while(left<=right){
            int mid = left+(right-left)/2;
            if(arr[mid]>arr[mid+1]){
                ret = mid;
                right =mid-1;
            }else{
                left = mid +1;
            }
        }
        return ret;
    }

}
